package cn.dt70.controller;

import cn.dt70.pojo.AqbUser;
import cn.dt70.service.AqbUserService;
import cn.dt70.utils.PageSupport;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller

@RequestMapping("/backend/")
public class BackendController {
    @Resource
    private AqbUserService userService;

//    用户信息列表
    @RequestMapping("userInfoList")
    public String userinfoList(@RequestParam(value = "userCode",required = false)String userCode,
                               @RequestParam(value = "userName",required = false)String userName,
                               PageSupport ph, Model model, HttpSession session){
//        if(session.getAttribute(Constrants.BACKEND_USER) == null){
//            return "";
//        }
        List<AqbUser> userList = userService.getAllUserInfo(userCode,userName,ph);
        model.addAttribute("userCode",userCode);
        model.addAttribute("userName",userName);
        model.addAttribute("userInfoList",userList);
        //分页信息
        model.addAttribute("currentPageNo",ph.getCurrentPageNo());
        model.addAttribute("totalCount",ph.getTotalCount());
        model.addAttribute("totalPageCount",ph.getTotalPageCount());
        return "backend/userInfoList";
    }

//    后台欢迎页面
    @RequestMapping("welcome")
    public String welcome(){
        return "backend/main";
    }

//    用户详细信息页面
    @RequestMapping("getUserInfoById")
    public String getUserInfoById(@RequestParam(value = "userCode",required = false) String userCode,
                                    Model model){
        AqbUser aqbUser =userService.getByUserCode(userCode);
        model.addAttribute("userCode",userCode);
        return "";
  }
}
